
<style type="text/css">
@import "style/jquery.countdown.css";
#TimerForm {
	width: 240px; height: 45px; 
}
body {
	font-family:sans-serif;
	margin-top:50px;
}
</style>

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.countdown.js"></script>
<script type="text/javascript">
function SetTimer(CountDown, begin) {
	$('#TimerDiv').countdown('destroy');
	var austDay = new Date();
	var austDay = new Date(austDay.getTime() + CountDown * 1000);
	if(begin == 1){
		$('#TimerDiv').countdown({until: austDay});
	}
};
</script>


<script type="text/javascript" >
function createXMLHttpRequest(){
  // See http://en.wikipedia.org/wiki/XMLHttpRequest
  // Provide the XMLHttpRequest class for IE 5.x-6.x:
  if( typeof XMLHttpRequest == "undefined" ) XMLHttpRequest = function() {
    try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch(e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch(e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP") } catch(e) {}
    try { return new ActiveXObject("Microsoft.XMLHTTP") } catch(e) {}
    throw new Error( "This browser does not support XMLHttpRequest." )
  };
  return new XMLHttpRequest();
}

var AJAX = createXMLHttpRequest();

function handler() {
	if(AJAX.readyState == 4 && AJAX.status == 200) {
		var json = eval('(' + AJAX.responseText +')');
		if(json.status != -1){
			document.getElementById("timertext").innerHTML = "You have "+json.timer+" seconds.";
			document.getElementById("statustext").innerHTML = "The question is ";
			if(json.status = 1){
				document.getElementById("statustext").innerHTML += "<strong>open!</strong> ";
			}else{
				document.getElementById("statustext").innerHTML += "<strong>closed :(</strong> ";
			}
			//start timer!
			SetTimer(json.timer, json.status);
		}else {
			alert("No rows found!");
		}
	}else if (AJAX.readyState == 4 && AJAX.status != 200) {
		alert("Something went wrong");
	}
}

function getTimer(){
	var questionid = "11";
	var params = "questionid="+questionid;

	AJAX = createXMLHttpRequest();
	AJAX.onreadystatechange = handler;
	AJAX.open("POST", "timerServlet");
	AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	AJAX.send(params);
}
</script> 
